package com.yto.hrreport.event.buttons.superbutton {
	import com.yto.hrreport.command.ReportCommand;
	
	import flash.events.Event;
	
	import mx.containers.Canvas;
	import mx.controls.Button;
	import mx.controls.TextInput;
	
	public class ButtonEvent {
		
		public var btnWidth : int = 80;
		public var txtWidth : int = 150;
		private var param : Object;
		
		public function ButtonEvent() {
			
		}
		
		public function updateButtons(event:Event , type : String , headCanvas : Canvas , success : Boolean) : void {
			
			var parentName : String = headCanvas.name.split("_")[0];
			param = ReportCommand.getInstance(parentName).initParam("updateButtons");
			
			switch(type) {
				
				case "add" : 
					Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = false;
					
					Button(headCanvas.getChildByName(parentName + "_btnCard")).label = "列表显示";
					Button(headCanvas.getChildByName(parentName + "_btnCard")).left = 5 + btnWidth * 7;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).visible = true;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).visible = true;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = true;
					
					TextInput(param.headCard.getChildByName(parentName + "_txtBillType")).text = parentName;
					TextInput(param.headCard.getChildByName(parentName + "_txtPeriod")).enabled = true;
					
					break;
				
				case "cancle" : 
					
					if(success) {
						Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = false;
						
						TextInput(param.headCard.getChildByName(parentName + "_txtPeriod")).enabled = false;
					}
					
					break;
				
				case "list" :
					
					Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).visible = false;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).left = 5 + btnWidth * 5;
					
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).visible = false;
					break;
				
				case "card" :
					
					Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).visible = true;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).left = 5 + btnWidth * 7;
					
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).visible = true;
					
					break;
				
				case "save" : 
					Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = true;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).visible = true;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).visible = true;
					TextInput(param.headCard.getChildByName(parentName + "_txtPeriod")).enabled = false;
					
					break;
				
				case "sysTree_ItemChange" : 
					
					if(success) {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
					} else {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
					}	
					
					break;
				
				case "sysTree_ItemChange_template" : 
					
					if(success) {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
					} else {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
					}	
					
					break;
				
				case "tempAdd" : 
					
					if(success) {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = false;
					} 
					
					break;
				
				case "tempDelete" : 
					
					if(success) {
						
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
						
					}
					
					break;
				
				case "sysEdit" :
					
					if(success) {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = false;
					} else {
						Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
						Button(headCanvas.getChildByName(parentName + "_btnEdit")).enabled = true;
						Button(headCanvas.getChildByName(parentName + "_btnRefresh")).enabled = true;
					}
					
					break;
				
				default :
					
					Button(headCanvas.getChildByName(parentName + "_btnQuery")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnSave")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnDelete")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnExport")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCard")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnCancle")).visible = false;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).enabled = false;
					Button(headCanvas.getChildByName(parentName + "_btnStatistic")).visible = false;
					
					break;
				
			}
			
		}
	}
}